<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/jsp/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息编辑窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <%--<link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">--%>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"
          rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min.css?v=4.0.0" rel="stylesheet">
    <base target="_blank">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/plugins/jsTree/style.min.css"
          rel="stylesheet">
    <style>
        .jstree-open > .jstree-anchor > .fa-folder:before {
            content: "\f07c"
        }

        .jstree-default .jstree-icon.none {
            width: 0
        }
    </style>
</head>
<body class="gray-bg">


<div class="wrapper wrapper-content">
    <div class="panel-body">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form onsubmit="return  false" class="form-horizontal" id="offlineCardForm">
                        <input id="offlineCard_id"  name="pofflineCard.id" type="hidden"/>

                        <div class="form-group">
                            <label class="col-sm-8 control-label" style="color: red;">添加成功后券额和生成数量不可修改，请谨慎填写!</label>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">名    称：</label>
                            <div class="col-sm-8">
                                <input id="offlineCard_name" value="${offlineCard.name}" name="pofflineCard.name"
                                       class="form-control" type="text"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">券    额：(单位:元)</label>
                            <div class="col-sm-8">
                                <input id="offlineCard_cardTotal2" value="${offlineCard.cardTotal}"  class="form-control" type="text"
                                       onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')">
                                <input id="offlineCard_cardTotal"  name="pofflineCard.cardTotal"  type="hidden">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">生成数量：(最大50000条)</label>
                            <div class="col-sm-8">
                                <input id="offlineCard_cardCount" value="${offlineCard.cardCount}" name="pofflineCard.cardCount"
                                       onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                       class="form-control" type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" onclick="doSubmit();">提交</button>
                                <button id="btn_close" class="btn btn-primary" type="button">关闭</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>




<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/jsTree/jstree.js"></script>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>

<script>

    var ajaxpath='${pageContext.request.contextPath}';
    $(function () {
        $('#offlineCard_id').val('${id}');
    });
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引



    //关闭iframe
    $('#btn_close').click(function () {
        parent.layer.close(index);
    });





    function doSubmit() {
        var name = $("#offlineCard_name").val();//名称
        var cardTotal2 = $("#offlineCard_cardTotal2").val();//显示金额 元
        var cardCount = $("#offlineCard_cardCount").val();//生产数量
        var  cardTotal=Math.floor(numMulti(cardTotal2,100));  //操作金额 分
        $("#offlineCard_cardTotal").val(cardTotal);  //操作金额 分

        var isOk = true;
        if (isNullOrEmpty(name)) {
            alert("请输入名称");
            isOk = false;
        }
        if (isNullOrEmpty(cardTotal2)) {
            alert("请输入金额");
            isOk = false;
        }
        if (isNullOrEmpty(cardCount)) {
            alert("请输入数量");
            isOk = false;
        }
        if (parseFloat(cardTotal2)<1) {
            alert("劵额必须大于0");
            isOk = false;
        }
        if (parseFloat(cardCount)<1 || parseFloat(cardCount)>50000) {
            alert("数量填写范围1~50000");
            isOk = false;
        }
        if(isNullOrEmpty(cardTotal)){
            alert("金额异常");
            isOk = false;
        }
        if(!isOk){
            return;
        }



        $.ajax({
            url: ajaxpath+'/offlineCard/doSave.ac',// 跳转到 action
            data: $("#offlineCardForm").serialize(),
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
                if (data == "success") {
                    alert("操作成功！");
                    parent.layer.close(index);
                } else {
                    alert(data);
                }
            },
            error: function () {
                alert("操作失败！");
            }
        });



    }



    //true:是空 false:不为空
    function isNullOrEmpty(strVal) {
        if (strVal == null || strVal == undefined || strVal == '') {
            return true;
        } else {
            return false;
        }
    };

    /**
     * 乘法运算，避免数据相乘小数点后产生多位数和计算精度损失。
     *
     * @param num1被乘数 | num2乘数
     */
    function numMulti(num1, num2) {
        var baseNum = 0;
        try {
            baseNum += num1.toString().split(".")[1].length;
        } catch (e) {
        }
        try {
            baseNum += num2.toString().split(".")[1].length;
        } catch (e) {
        }
        return Number(num1.toString().replace(".", "")) * Number(num2.toString().replace(".", "")) / Math.pow(10, baseNum);
    };

</script>

</body>

</html>

